package com.bbva.kyfb.kyfbjpatlbh.dominiotlbh;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.Id;
import javax.persistence.PersistenceContext;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.transaction.annotation.Transactional;

/**
 * The Class Ttlsbval.
 */
@Configurable
@Entity
@Table(name = "TTLSBVAL",schema = "TLSB")
@RooJavaBean
@RooToString
@RooEntity(versionField = "", persistenceUnit="persistenceUnitTLBH", table = "TTLSBVAL", schema = "TLSB")
@PersistenceContext(unitName="persistenceUnitTLBH")
@RooDbManaged(automaticallyDelete = true)
public class Ttlsbval {

	/** The cod vali. */
	@Id
    @Column(name = "COD_VALI", nullable = false,columnDefinition = "CHAR", length = 5)
    @NotNull
    private String codVali;

	/** The des vali. */
	@Column(name = "DES_VALI",columnDefinition = "CHAR", length = 20)
    private String desVali;

	/** The des urlval. */
	@Column(name = "DES_URLVAL",columnDefinition = "CHAR", length = 80)
    private String desUrlval;

	/**
	 * Gets the cod vali.
	 *
	 * @return the cod vali
	 */
	public String getCodVali() {
        return this.codVali;
    }

	/**
	 * Sets the cod vali.
	 *
	 * @param id the new cod vali
	 */
	public void setCodVali(String id) {
        this.codVali = id;
    }

	/**
	 * Gets the des vali.
	 *
	 * @return the des vali
	 */
	public String getDesVali() {
        return this.desVali;
    }

	/**
	 * Sets the des vali.
	 *
	 * @param desVali the new des vali
	 */
	public void setDesVali(String desVali) {
        this.desVali = desVali;
    }

	/**
	 * Gets the des urlval.
	 *
	 * @return the des urlval
	 */
	public String getDesUrlval() {
        return this.desUrlval;
    }

	/**
	 * Sets the des urlval.
	 *
	 * @param desUrlval the new des urlval
	 */
	public void setDesUrlval(String desUrlval) {
        this.desUrlval = desUrlval;
    }

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("CodVali: ").append(getCodVali()).append(", ");
        sb.append("DesUrlval: ").append(getDesUrlval()).append(", ");
        sb.append("DesVali: ").append(getDesVali());
        return sb.toString();
    }

	/** The entity manager. */
	@PersistenceContext
    transient EntityManager entityManager;


	/**
	 * Persist.
	 */
	@Transactional(value="tlbh")
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.persist(this);
    }

	/**
	 * Removes the.
	 */
	@Transactional(value="tlbh")
    public void remove() {
        if (this.entityManager == null) this.entityManager = entityManager();
        if (this.entityManager.contains(this)) {
            this.entityManager.remove(this);
        } else {
            Ttlsbval attached = Ttlsbval.findTtlsbval(this.codVali);
            this.entityManager.remove(attached);
        }
    }

	/**
	 * Flush.
	 */
	@Transactional(value="tlbh")
    public void flush() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.flush();
    }

	/**
	 * Clear.
	 */
	@Transactional(value="tlbh")
    public void clear() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.clear();
    }

	/**
	 * Merge.
	 *
	 * @return the ttlsbval
	 */
	@Transactional(value="tlbh")
    public Ttlsbval merge() {
        if (this.entityManager == null) this.entityManager = entityManager();
        Ttlsbval merged = this.entityManager.merge(this);
        this.entityManager.flush();
        return merged;
    }

	/**
	 * Entity manager.
	 *
	 * @return the entity manager
	 */
	public static final EntityManager entityManager() {
        EntityManager em = new Ttlsbval().entityManager;
        if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
        return em;
    }

	
	/**
	 * Count ttlsbvals.
	 *
	 * @return the long
	 */
	@Transactional(value="tlbh")
	public static long countTtlsbvals() {
        return entityManager().createQuery("SELECT COUNT(o) FROM Ttlsbval o", Long.class).getSingleResult();
    }

	
	/**
	 * Find all ttlsbvals.
	 *
	 * @return the list
	 */
	@Transactional(value="tlbh")
	public static List<Ttlsbval> findAllTtlsbvals() {
        return entityManager().createQuery("SELECT o FROM Ttlsbval o", Ttlsbval.class).getResultList();
    }

	
	/**
	 * Find ttlsbval.
	 *
	 * @param codVali the cod vali
	 * @return the ttlsbval
	 */
	@Transactional(value="tlbh")
	public static Ttlsbval findTtlsbval(String codVali) {
        if (codVali == null || codVali.length() == 0) return null;
        return entityManager().find(Ttlsbval.class, codVali);
    }

	
	/**
	 * Find ttlsbval entries.
	 *
	 * @param firstResult the first result
	 * @param maxResults the max results
	 * @return the list
	 */
	@Transactional(value="tlbh")
	public static List<Ttlsbval> findTtlsbvalEntries(int firstResult, int maxResults) {
        return entityManager().createQuery("SELECT o FROM Ttlsbval o", Ttlsbval.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
    }

}
